package com.superman.supermarket.client.composite.home.recommandgoods;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.widget.lazy.LazyImage;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.utils.ActivityJumpUrl;

/**
 * 推荐的商品模块
 * 
 * @author superman
 * @version 2018年7月21日下午11:13:53
 */
public class RecommandGoodsModule extends Composite implements IUIModule {

	interface RecommandGoodsModuleUiBinder extends UiBinder<Widget, RecommandGoodsModule> {
	}

	private static RecommandGoodsModuleUiBinder uiBinder = GWT.create(RecommandGoodsModuleUiBinder.class);

	@UiField
	LazyImage image;
	@UiField
	HTML namehtml, pricehtml;
	private String spuId, prop;

	@UiField
	FlowPanel wrapperpanel;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年7月21日 下午11:13:55
	 */
	public RecommandGoodsModule() {
		initWidget(uiBinder.createAndBindUi(this));

		wrapperpanel.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				ActivityJumpUrl.pushToSkuDetailPage(spuId, prop);
			}
		}, ClickEvent.getType());
	}

	@Override
	public Map<String, Object> getData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setData(Map<String, Object> map) {

		this.spuId = String.valueOf(map.get("SPU_ID"));
		this.prop = String.valueOf(map.get("PROPERTIES"));

		image.setUrl(String.valueOf(map.get("MIDDLE_PIC")));
		namehtml.setText(String.valueOf(map.get("NAME")));
		pricehtml.setText("¥ " + map.get("SALE_PRICE"));
	}

}
